package com.pool;

import java.awt.Color;
import java.awt.Dimension;
import java.awt.Graphics;
import java.awt.Rectangle;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import java.awt.event.MouseMotionListener;

import javax.swing.JComponent;

import com.pool.objects.Table;

public class Renderer extends JComponent implements MouseListener, MouseMotionListener {
	
	private static final long serialVersionUID = -1371883222544579013L;
	private Table table = new Table();
	
	private int[] orgCoords = new int[2];
	
	public Renderer() {
		super();

		setMinimumSize(new Dimension(0, 0));
		setPreferredSize(new Dimension(800, 600));
		
		addMouseListener(this);
		addMouseMotionListener(this);
	}

    @Override
    public void paint(Graphics g) {
        int w = getWidth(), h = getHeight();
        
        Color old = g.getColor();
        
        g.setColor(new Color(0, 0, 0));
        g.fillRect(0, 0, w, h);
        
        table.paint(g, new Rectangle(0, 0, w, h));
        
        g.setColor(old);
    }

	@Override
	public void mouseDragged(MouseEvent e) {
		table.mouseEvent(orgCoords, new int[] {e.getX(), e.getY()});
	}

	@Override
	public void mouseMoved(MouseEvent e) {
		
	}

	@Override
	public void mouseClicked(MouseEvent e) {
		
	}

	@Override
	public void mouseEntered(MouseEvent e) {
		
	}

	@Override
	public void mouseExited(MouseEvent e) {
		
	}

	@Override
	public void mousePressed(MouseEvent e) {
		orgCoords[0] = e.getX();
		orgCoords[1] = e.getY();
	}

	@Override
	public void mouseReleased(MouseEvent e) {
		
	}
    
}
